﻿using EasyDDD.AdminModule.Domain.AggregateSysAdmin;
using EasyDDD.Application;
// using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyDDD.AdminModule.Application.CommandsSysAdmin
{
    public record SysAdminSetRoleCommand : ICommand<SysAdmin>
    {
        public Guid Id { get; set; } = default!;

        public Guid[] RoleIds { get; set; } = default!;
    }

    public class SysAdminSetRoleCommandHandler(
        //IMapper mapper,
        Repository.SysAdminRepository repository,
        //UserManager<Domain.SysAdminAggregate.ApplicationUser> userManager,
        ILogger<SysAdminSetRoleCommandHandler> logger)
        : ICommandHandler<SysAdminSetRoleCommand, SysAdmin>
    {
        public async Task<SysAdmin> Handle(SysAdminSetRoleCommand request, CancellationToken cancellationToken)
        {
            logger.LogDebug("命令  SysAdminSetRoleCommandHandler");
            var entity = await repository.GetAsync(request.Id, cancellationToken);
            entity.SetUserRoleList(request.RoleIds);
            return entity;
        }
    }
}
